package com.devicemantra.coordinate.ds.tests;
import com.devicemantra.coordinate.dataobjects.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.*;

import com.devicemantra.coordinate.dataobjects.CDepartmentFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@SuppressWarnings("serial")
public class ViewSubDepartment extends HttpServlet 
{
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException 
	{
		resp.setContentType("text/html");
		/* First let us populate a list of Department objects */
		List<CDepartment> lDeptList = CDepartmentFactory.getAllDepartments();
		req.setAttribute("DEPT_LIST", lDeptList);
		try {
			req.getRequestDispatcher("add_subdept.jsp").forward(req,resp);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
		
		
		/* Check whether a department exists with the same name */
		/*if(DepartmentFactory.checkDepartmentExists(req.getParameter("dept_name")))
		{
			resp.getOutputStream().println("[SubDepartment Check failed] <BR> ");
		}
		else
		{
			resp.getOutputStream().println("[SubDepartment Check passed] <BR>");
		}
		
		SubDepartment lSubDept = SubDepartmentFactory.createNewSubDepartment("", "");
		if( lSubDept != null)
		{
			pm.makePersistent(lSubDept);
			pm.close();
			resp.getOutputStream().print("SubDepartment Added " + lSubDept.getSubDepartmentName());
		}
		else
		{
			resp.getOutputStream().print("SubDepartment with that name already exists ");
		}*/
		
		
		
	}
}
